<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import echarts from 'echarts'
require('./mixins/macarons') // echarts theme

import resize from './mixins/resize.js'

const animationDuration = 3000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    }
  },
  data() {
    return {
      chart: null,
      newchart:[0, 0, 0, 0, 0, 0],    
    }
  },
  mounted() {
    
    this.$nextTick(() => {
      this.axios({
        method: "GET",
        url: "https://admin.xiaoheihe.work/bapi/dataraddar",
      }).then(res=>{
        this.newchart = res.data.newchart
        console.log("newchart:"+this.newchart)
        this.initChart(this.newchart) 
        
      })

    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
   
    initChart(newchart) {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption({
        tooltip: {
          trigger: 'item',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        radar: {
          radius: '66%',
          center: ['50%', '42%'],
          splitNumber: 8,
          splitArea: {
            areaStyle: {
              color: 'rgba(127,95,132,.3)',
              opacity: 1,
              shadowBlur: 45,
              shadowColor: 'rgba(0,0,0,.5)',
              shadowOffsetX: 0,
              shadowOffsetY: 15
            }
          },
          indicator: [
            { name: '用户总量', max: newchart[0]*5 },
            { name: '总交易量', max: newchart[1]*2 },
            { name: '总交易金额', max: newchart[2]*4 },
            { name: '月订单数量', max: newchart[3]*2 },
            { name: '总商品数量', max: newchart[4]*3 },
            { name: '月活跃用户', max: newchart[5]*2}
          ]
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['数据总览']
        },
        series: [{
          name: '发展计划',
          type: 'radar',
          symbolSize: 0,
          areaStyle: {
            normal: {
              shadowBlur: 13,
              shadowColor: 'rgba(0,0,0,.2)',
              shadowOffsetX: 0,
              shadowOffsetY: 10,
              opacity: 1
            }
          },
          data: [
            {
              value: newchart,
              name: '数据总览'
            },
          ],
          animationDuration: animationDuration
        }]
      })
    }
  }
}
</script>
